import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default({
  namespaced:true,
  state: {
    isOnline:window.localStorage.getItem('staff'|| '[]') != null ,
    senior:window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).senior,
    password:'',
    name: window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).name,
    account:window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).account,
    Pcash:window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).Pcash,
    Ppurchase:window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).Ppurchase,
    Pplan:window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).Pplan,
    Pimpower:window.localStorage.getItem('staff' || '[]') == null ? null : JSON.parse(window.localStorage.getItem('staff' || '[]')).Pimpower,
    Proot:window.localStorage.getItem('staff' || '[]') == null ?null : JSON.parse(window.localStorage.getItem('staff' || '[]')).Proot,
  },
  mutations: {
    login (state, staff) {
      state.senior=staff.senior;
      state.password=staff.password;
      state.name = staff.name||state.name;
      state.account=staff.account||state.account;
      state.Pcash=staff.Pcash||state.Pcash;
      state.Ppurchase = staff.Ppurchase||state.Ppurchase;
      state.Pplan=staff.Pplan||state.Pplan;
      state.Pimpower=staff.Pimpower||state.Pimpower;
      state.Proot=staff.Proot||state.Proot;
      state.isOnline=true;
      window.localStorage.setItem('staff', JSON.stringify(staff))
    },
    logout(state,staff){
      state.senior=null;
      state.isOnline=false;
      state.password=null;
      state.account=null;
      state.Pcash=null;
      state.Ppurchase=null;
      state.Pplan=null;
      state.Proot=null;
      state.Pimpower=null;
      state.name=null;
      window.localStorage.removeItem('staff');
      console.log('staff log out')
    }
  }
})



